package com.zhou.org.common;

import lombok.Data;

import java.io.Serializable;
import java.util.Objects;
import java.util.regex.Pattern;

/**
 * @author lang.zhou
 * @since 2023/3/27 10:14
 */
@Data
public class MenuUrlPattern implements Serializable {
    private static final long serialVersionUID = 1L;

    private Pattern pattern;

    private String originUrl;

    private Long menuId;
    private String menuName;

    public boolean match(String input){
        if(pattern == null){
            return originUrl.equalsIgnoreCase(input);
        }else{
            return pattern.matcher(input).matches();
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MenuUrlPattern that = (MenuUrlPattern) o;
        return Objects.equals(originUrl, that.originUrl);
    }

    @Override
    public int hashCode() {
        return Objects.hash(originUrl);
    }
}
